import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import whoami from '@feidao/web/atom/browser/msg/whoami';
import { send_msg as url } from './config';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import fire from '@feidao/web/atom/browser/msg/fire';
// import get from '@feidao/web/atom/browser/local/get';
// import set from '@feidao/web/atom/browser/local/set';
import XL from '@feidao/widgets/fd-w000018';
import P01 from './P01'; //
import P02 from './P02'; //
import P03 from './P03'; //
// import P02 from './P04'; // 渲染空模板
// import P05 from './P05'; // 渲染分页

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	const user = await whoami(url + '/whoami');
	const teacher_no = user.usercode;
	const user_name = user.user_name;
	const name1 = fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-name="user_name"]')
	name1.innerHTML = user_name
	const res = await nodejs<{ dataArray: Array<{}> }>(url, 'top_menu/pre_class_classes_query', { teacher_no }, false, false);
	render(fd, JSON.stringify(res.dataArray), P01, 'P01', 'inner');

	const teaching_class_id = fd.data.params['teaching_class_id'];
	const course_no = fd.data.params['course_no'];
	const version_number = fd.data.params['version_number'];

	const res1 = await nodejs<{ dataArray: Array<{}> }>(url, 'top_menu/pre_class_classes_find', { teaching_class_id }, false, false);

	const teaching_class = res1.dataArray[0]['teaching_class'];
	const res2 = await nodejs<{ dataArray: Array<{}> }>(url, 'top_menu/course_query', { filter: { course_no } }, false, false);
	render(fd, res2.dataArray[0], P02, 'P02', 'inner');

	const xiala1 = fd.data.node.querySelector<XL>('#xiala1');
	xiala1.set_selected(teaching_class);

	const data = [{ teaching_class_id: teaching_class_id, course_no: course_no, version_number: version_number, teaching_class: teaching_class }];
	console.log(data, 's---------------------')
	render(fd, data[0], P03, 'P03', 'inner');

	const name = fd.data.node.getAttribute('data-feidao-name'); fd.data.node.querySelector('[data-feidao-id="name"]').innerHTML = name;
	const zj = fd.data.node.getAttribute('data-feidao-id');
	fire(zj, 'ec-001', { course_no, teaching_class_id, version_number });
	// const name1 = fd.data.node.getAttribute('data-feidao-name1'); fd.data.node.querySelector('[data-feidao-name1="user_name"]').innerHTML = name1;

}
